package ar.fiuba.logger.formatRules;

import java.util.Objects;

import ar.fiuba.logger.LogMessageInterface;

/**
 * The Class LogLevelNameFormatRule.
 * 
 * This class implements the line number format rule. This rule prints the current line number.
 */
public class LogLevelNameFormatRule implements FormatRuleInterface {
  /**
   * The rule code. This string will be replaced by the rule result.
   */
  private static final String ruleCode = "p";

  /*
   * (non-Javadoc)
   * 
   * @see fiuba.logger.formatRules.FormatRuleInterface#applyFormatRule(java.lang.String)
   */
  @Override
  public String applyFormatRule(String unformattedMessage, LogMessageInterface logMessage) {
    final String regex = "(?<!%)%" + ruleCode;

    return unformattedMessage.replaceAll(regex, logMessage.getLogLevel().name());
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(Object object) {
    if (this == object)
      return true;
    if (object == null)
      return false;
    if (getClass() != object.getClass())
      return false;
    return true;
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode() {
    return Objects.hashCode(this.getClass());
  }

}
